import org.dom4j.*;

import java.io.IOException;
import java.util.HashMap;

/**
 * @author ml
 * @create 2017-07-28--17:49
 */
public class MsgService_rabbit {

    private String basePath;
    private String pfuserName;
    private String estateName;
    private String dataBaseIp;
    private String serverIp;
    public MsgService_rabbit(String basePath, String pfuserName, String estateName, String dataBaseIp, String serverIp){
        this.basePath= basePath;
        this.pfuserName=pfuserName;
        this.estateName=estateName;
        this.dataBaseIp=dataBaseIp;
        this.serverIp=serverIp;

    }

    public void changexml() throws Exception{
        Document doc=XmlUtil.parse(basePath+FilePathEnum.MSGSERVICE_RABBITMQ.getValue());
        updateDocByXPATH(doc);

    }

    public void updateDocByXPATH(Document doc) throws DocumentException, IOException {

        Element rootElm = doc.getRootElement();

        System.out.println(rootElm.getName());

        HashMap map=new HashMap();
        map.put("design",rootElm.getNamespaceURI());


        //rabbit
        Element rroot=doc.getRootElement();
        XPath rpath=doc.createXPath("//design:bean[@id='connectionFactory']/design:constructor-arg");

        rpath.setNamespaceURIs(map);

        Element relement= (Element) rpath.selectSingleNode(doc);

        Attribute rabbitip=relement.attribute("value");
        System.out.println("rabbitip="+rabbitip.getValue());

        rabbitip.setValue(serverIp);

        XmlUtil.saveDocument(doc,basePath+FilePathEnum.MSGSERVICE_RABBITMQ.getValue());







    }
}
